$('#reset').click(function(){
    $('input').val('');
})

jQuery.Huitab = function (tabBar, tabCon, class_name, tabEvent, i) {
    var $tab_menu = $(tabBar);
    // 初始化操作
    $tab_menu.removeClass(class_name);
    $(tabBar).eq(i).addClass(class_name);
    $(tabCon).hide();
    $(tabCon).eq(i).show();
    $tab_menu.bind(tabEvent, function () {
        $tab_menu.removeClass(class_name);
        $(this).addClass(class_name);
        var index = $tab_menu.index(this);
        $(tabCon).hide();
        $(tabCon).eq(index).show();
    });
}

$(function () {
    $.Huitab("#tab_goods .tabBar span", "#tab_goods .tabCon", "current", "click", "0")
});
// #tab_demo 父级id
// #tab_demo .tabBar span 控制条
// #tab_demo .tabCon 内容区
// click 事件 点击切换，可以换成mousemove 移动鼠标切换
// 1	默认第2个tab为当前状态（从0开始）

$(function () {
    $('.skin-minimal input').iCheck({
        checkboxClass: 'icheckbox-blue',
        radioClass: 'iradio-blue',
        increaseArea: '20%'
    })
});

var id = getQueryString('topicId');
var arr1 = new Array(); //1级分类ID
var arr2 = new Array(); //2级分类ID
var arr3 = new Array(); //3级分类ID
var applcationRange; //适用范围 0:全部分类 1:指定分类 2:指定场景
var arr4 = new Array();//根据二级查询的一级分类ID 数组
var arr5 = new Array();//根据三级查询的二级分类ID 数组
$.ajax({
    url: root.couponInter.coupon_getCouponTopicById,
    cache: false,  //禁用缓存
    type: "POST",
    dataType:'json',
    async:false,
    // contentType: "application/json",
    data: {
        "topicId":id
    },
    success: function (data) {
        console.log(data);
        $('#applPaidType').removeClass('icheckbox-blue checked');
        if (data.couponTopic.applPaidType == '1001,1301,1401,1101,1201') {
            document.getElementById("checkbox_id").checked = true;
            $("input[name='paidType']").each(function () {
                $(this).prop("checked", true);
            });
        } else {
            var groupCheckbox = data.couponTopic.applPaidType.split(",");
            for (var i = 0; i < groupCheckbox.length; i++) {
                if (groupCheckbox[i] == '1001') {
                    $('#paidType1').prop("checked", true);
                }
                if (groupCheckbox[i] == '1301') {
                    $('#paidType2').prop("checked", true);
                }
                if (groupCheckbox[i] == '1401') {
                    $('#paidType3').prop("checked", true);
                }
                if (groupCheckbox[i] == '1101') {
                    $('#paidType4').prop("checked", true);
                }
                if (groupCheckbox[i] == '1201') {
                    $('#paidType5').prop("checked", true);
                }
                if (groupCheckbox[i] == '1701') {
                    $('#paidType6').prop("checked", true);
                }
            }
        }
        $('#applCategoryIntroduce').val(data.couponTopic.applCategoryIntroduce);
        $('#topicUrl').val(data.couponTopic.topicUrl);
        //状态
        if(data.couponTopic.topicStatus==10){
            $('#topicStatus').html('已生效')
            $('#descReason').hide();
        }else if(data.couponTopic.topicStatus==30){
            $('#topicStatus').html('已失效')
            $('#descReason').hide();
        }else if(data.couponTopic.topicStatus==40){
            $('#topicStatus').html('强制失效')
        }
        if(data.couponTopic.topicUseTag==20){
            $('#topicUseTag').html("是");
        }else {
            $('#topicUseTag').html("否");
        }
        if(data.couponTopic.priceType==20){
            $('#priceType1').prop("checked", true);
        }else if(data.couponTopic.priceType==10){
            $('#priceType2').prop("checked", true);
        }else if(data.couponTopic.priceType==0){
            $('#radio_id').prop("checked", true);
        }

        //描述
        $('#description').html(data.couponTopic.description);
        $('#topicCode').html(data.couponTopic.topicCode);
        $('#topicName').html(data.couponTopic.topicName);
        $('#amount').html(data.couponTopic.amount);
        $('#totalCount').html(data.couponTopic.totalCount);
        $('#createUsername').html(data.couponTopic.createUsername);
        $('#createDept').html(data.couponTopic.createDept);
        $('#reason').html(data.couponTopic.reason);
        $('#introduction').html(data.couponTopic.introduction);
        $('#countPrice').html(data.couponTopic.totalAmount);
        //使用门槛
        if(data.couponTopic.useCondition==0 && data.couponTopic.topicType==10){
            $('#condition').html('不限订单金额');
        }else if(data.couponTopic.useCondition==0 && data.couponTopic.topicType==20){
            $('#condition').html('不限运费金额');
        }else if(data.couponTopic.topicType==20){
            $('#condition').html('单笔订单中运费金额满'+data.couponTopic.useCondition+'元使用');
        }
        else if(data.couponTopic.topicType==10){
            $('#useCondition').html(data.couponTopic.useCondition);
        }
        // 类型
        if(data.couponTopic.topicType==10){
            $('#topicType').html('满减券')
        }else if(data.couponTopic.topicType==20){
            $('#topicType').html('运费券')
        }
        //有效时间
        if(data.couponTopic.dayNumber==0){
            if(data.couponTopic.useEndtime==null){
                $('#useTime').html(data.couponTopic.useBegtime+" - 不限");
            }else{
                $('#useTime').html(data.couponTopic.useBegtime+"到"+data.couponTopic.useEndtime+"之内有效");
            }
        }else{
            $('#dayNumber').html(data.couponTopic.dayNumber);
        }
        //端口
        if(data.couponTopic.applPort==0){
            $('#applPort').html('不限');
        }else if(data.couponTopic.applPort==1){
            $('#applPort').html('电脑端');
        }else if(data.couponTopic.applPort==2){
            $('#applPort').html('移动端');
        }
        //商品范围
        if(data.couponTopic.applRange==1){
            $('#applRange').html('指定品类');
        }else if(data.couponTopic.applRange==2){
            $('#applRange').html('指定场景');
        }else if(data.couponTopic.applRange==3 && data.couponTopic.topicType==10){
            $('#applRange').html('指定商品');
            $('#line').hide();
            $('#category').hide();
            $('#applCate').hide();
        }else if(data.couponTopic.applRange==0 && data.couponTopic.topicType==20){
            $('#line').hide();
            $('#category').hide();
            $('#applProduct').hide();
            $('#tab_goods').hide();
            $('#applCate').hide();
        }
        else{
            $('#applRange').html('全场通用');
        }
        //适用 排它
        if(data.couponTopic.applCate==1 && data.couponTopic.topicType==10){
            $('#applCate').html('适用品类');
        }else if(data.couponTopic.applCate==2 && data.couponTopic.topicType==10){
            $('#applCate').html('排除品类');
        }else if(data.couponTopic.applCate==0){
            $('#applCate').html('');
        }
        applcationRange = data.couponTopic.applRange;
        if(data.couponTopic.topicType==10){
            for(var i =0;i<data.oneCateIdSet.length;i++){
                arr4.push(data.oneCateIdSet[i]);
            }
            for(var i =0;i<data.twoCateIdSet.length;i++){
                arr5.push(data.twoCateIdSet[i]);
            }
            // console.log("arr4"+arr4);
            // console.log("arr5"+arr5);
            //保存的分类IDs
            // console.log(data.couponTopic.cateIds);
            var json2map = JSON.parse(data.couponTopic.cateIds);

            arr1 = json2map[1];
            arr2 = json2map[2];
            arr3 = json2map[3];
            arr4 = json2map[4];

            if(data.couponProducts.length > 0){

                var p = data.couponProducts[0].spuId.replace(/(^\s*)|(\s*$)/g, "").split(";").length;
                var k = data.couponProducts[0].skuId.replace(/(^\s*)|(\s*$)/g, "").split(";").length;
                var u = data.couponProducts[1].spuId.replace(/(^\s*)|(\s*$)/g, "").split(";").length;
                var o = data.couponProducts[1].skuId.replace(/(^\s*)|(\s*$)/g, "").split(";").length;

                if(data.couponProducts[0].spuId.replace(/(^\s*)|(\s*$)/g, "").split(";")[0]==''){
                    p = 0;
                };
                if(data.couponProducts[0].skuId.replace(/(^\s*)|(\s*$)/g, "").split(";")[0]==''){
                    k = 0;
                };
                if(data.couponProducts[1].spuId.replace(/(^\s*)|(\s*$)/g, "").split(";")[0]==''){
                    u = 0;
                };
                if(data.couponProducts[1].skuId.replace(/(^\s*)|(\s*$)/g, "").split(";")[0]==''){
                    o = 0;
                };

                $('#applNumber').html(p+k);
                $('#removeNumber').html(u+o);

                $('#spuText').html(data.couponProducts[0].spuId);
                $('#skuText').html(data.couponProducts[0].skuId);
                $('#spuText1').html(data.couponProducts[1].spuId);
                $('#skuText1').html(data.couponProducts[1].skuId);
            }
        }
    },
    error: function () {
        $.Huimodalalert('失败！');
    }
});
$('#putout').attr('href',root.couponInter.coupon_exportProductExcel+id);

/*分类设置开始--------------------------------------------------------------------------------------------------------------*/
goods_listCategory1(1);

function goods_listCategory1(classNum) {
    var user_data = {
        category_level: classNum
    }
    var succCallBack = function(data, status, response) {
        if(data.errorCode == "0") {
            //全部分类(全场通用)
            if(applcationRange==0){
                for(var i = 0; i < data.data.length; i++) {
                    $("#classSet1").append('<li class="clearfix pl-10 mb-5"><div class="f-l pd-5"><input  name="classification01" type="checkbox" checked disabled value="' + data.data[i].category_id + '" class="checkbox" />' +
                        '<label class="pl-10">' + data.data[i].category_code + ' ' + data.data[i].category_name + '</label></div></li>')
                }
            }//if
            //指定分类
            //一级分类值为空
            else if(arr1.length==0 && arr2.length!=0) {
                for (var i = 0; i < data.data.length; i++) {
                    if(arr4.indexOf(data.data[i].category_id)!=-1){
                        $("#classSet1").append('<li class="clearfix pl-10 mb-5"><div class="f-l pd-5"><input  name="classification01"  checked disabled  type="checkbox" value="' + data.data[i].category_id + '" class="checkbox" />' +
                            '<lable class="pl-10" onclick="goods_listCategory2(2,'+data.data[i].category_id+')" >' + data.data[i].category_code + ' ' + data.data[i].category_name + '</lable></div></li>')
                    }else{
                        $("#classSet1").append('<li class="clearfix pl-10 mb-5"><div class="f-l pd-5"><input  name="classification01" disabled type="checkbox" value="' + data.data[i].category_id + '" class="checkbox" />' +
                            '<label  class="pl-10" >' + data.data[i].category_code + ' ' + data.data[i].category_name + '</label></div></li>')
                    }
                }//for
            }//if
            //一级分类值不为空
            else if(arr1.length!=0 && arr2.length!=0 ) {
                for (var i = 0; i < data.data.length; i++) {
                    if(arr4.indexOf(data.data[i].category_id)!=-1  || arr1.indexOf(String(data.data[i].category_id))!=-1){
                        $("#classSet1").append('<li class="clearfix pl-10 mb-5"><div class="f-l pd-5"><input  name="classification01"  checked  disabled type="checkbox" value="' + data.data[i].category_id + '" class="checkbox" />' +
                            '<lable class="pl-10" onclick="goods_listCategory2(2,'+data.data[i].category_id+')" >' + data.data[i].category_code + ' ' + data.data[i].category_name + '</lable></div></li>')
                    }else{
                        $("#classSet1").append('<li class="clearfix pl-10 mb-5"><div class="f-l pd-5"><input  name="classification01" disabled type="checkbox" value="' + data.data[i].category_id + '" class="checkbox" />' +
                            '<label  class="pl-10" >' + data.data[i].category_code + ' ' + data.data[i].category_name + '</label></div></li>')
                    }
                }//for
            }//if
            //一级分类值不为空
            else if(arr1.length!=0 && arr2.length==0 ) {
                for (var i = 0; i < data.data.length; i++) {
                    if(arr1.indexOf(String(data.data[i].category_id))!=-1 || arr4.indexOf(data.data[i].category_id)!=-1){
                        $("#classSet1").append('<li class="clearfix pl-10 mb-5"><div class="f-l pd-5"><input  name="classification01"  checked  disabled type="checkbox" value="' + data.data[i].category_id + '" class="checkbox" />' +
                            '<lable class="pl-10" onclick="goods_listCategory2(2,'+data.data[i].category_id+')" >' + data.data[i].category_code + ' ' + data.data[i].category_name + '</lable></div></li>')
                    }else{
                        $("#classSet1").append('<li class="clearfix pl-10 mb-5"><div class="f-l pd-5"><input  name="classification01" disabled type="checkbox" value="' + data.data[i].category_id + '" class="checkbox" />' +
                            '<label  class="pl-10" >' + data.data[i].category_code + ' ' + data.data[i].category_name + '</label></div></li>')
                    }
                }//for
            }//if
            //一级分类值不为空
            else if(arr1.length==0 && arr2.length==0 && arr3.length!=0 ) {
                for (var i = 0; i < data.data.length; i++) {
                    if(arr1.indexOf(String(data.data[i].category_id))!=-1 || arr4.indexOf(data.data[i].category_id)!=-1){
                        $("#classSet1").append('<li class="clearfix pl-10 mb-5"><div class="f-l pd-5"><input  name="classification01"  checked  disabled type="checkbox" value="' + data.data[i].category_id + '" class="checkbox" />' +
                            '<lable class="pl-10" onclick="goods_listCategory2(2,'+data.data[i].category_id+')" >' + data.data[i].category_code + ' ' + data.data[i].category_name + '</lable></div></li>')
                    }else{
                        $("#classSet1").append('<li class="clearfix pl-10 mb-5"><div class="f-l pd-5"><input  name="classification01" disabled type="checkbox" value="' + data.data[i].category_id + '" class="checkbox" />' +
                            '<label  class="pl-10" >' + data.data[i].category_code + ' ' + data.data[i].category_name + '</label></div></li>')
                    }
                }//for
            }//if
        }
    };
    return web.doAjax(root.goodsInter.goods_listCategory, 'post', user_data, succCallBack);
}

function goods_listCategory2(classNum, parentId) {
    sessionStorage.setItem("parentId2", parentId);
    $("#classDiv2").css({
        display: "none"
    });
    $("#classDiv3").css({
        display: "none"
    });
    $("#classDiv4").css({
        display: "none"
    });
    $("#classDiv2").css({
        display: "block"
    });
    $(".removeEl2").remove();
    var user_data = {
        // category_level: classNum,
        category_id: parentId
    }
var count = 0;
    var succCallBack = function (data, status, response) {
        for(var i = 0; i < data.data.length; i++) {
            if(arr2.indexOf(String(data.data[i].category_id))!=-1){
                count++;
            }
        }
        if (data.errorCode == "0") {
            if (data.data == null) {
                $("#classSet2").append('<li class="removeEl2 clearfix pl-10 mb-5">无数据</li>');
                $("#classSet2").append('<li  class="removeEl2 clearfix pl-10 mb-5" id="firstClassInp2" style="display: none"><div class="f-l pd-5"><label class="pl-10" id="addLabel2"></label></div></li>')
            } else {
                if(arr2.length!=0 && arr3.length==0){
                    for (var i = 0; i < data.data.length; i++) {
                        if(arr2.indexOf(String(data.data[i].category_id))!=-1){
                            $("#classSet2").append('<li class="removeEl2 clearfix pl-10 mb-5"><div class="f-l pd-5"><input  name="classification02" type="checkbox" checked disabled value="' + data.data[i].category_id + '" class="checkbox" />' +
                                '<label class="pl-10"  onclick="goods_listCategory3(3,'+data.data[i].category_id+')">' + data.data[i].category_code + ' ' + data.data[i].category_name + '</label></div></li>')
                        }else if(count==0){
                            $("#classSet2").append('<li class="removeEl2 clearfix pl-10 mb-5"><div class="f-l pd-5"><input  name="classification02" type="checkbox" checked disabled value="' + data.data[i].category_id + '" class="checkbox" />' +
                                '<label class="pl-10"  onclick="goods_listCategory3(3,'+data.data[i].category_id+')">' + data.data[i].category_code + ' ' + data.data[i].category_name + '</label></div></li>')
                        }else{
                            $("#classSet2").append('<li class="removeEl2 clearfix pl-10 mb-5"><div class="f-l pd-5"><input  name="classification02" type="checkbox" disabled value="' + data.data[i].category_id + '" class="checkbox" />' +
                                '<label class="pl-10" >' + data.data[i].category_code + ' ' + data.data[i].category_name + '</label></div></li>')
                        }
                    }//for
                    count = 0;
                }else if(arr2.length!=0 && arr3.length!=0) {
                    if(count==0){
                        for (var i = 0; i < data.data.length; i++) {
                            $("#classSet2").append('<li class="removeEl2 clearfix pl-10 mb-5"><div class="f-l pd-5"><input  name="classification02" type="checkbox" checked disabled value="' + data.data[i].category_id + '" class="checkbox" />' +
                                '<label class="pl-10" onclick="goods_listCategory3(3,'+data.data[i].category_id+')" >' + data.data[i].category_code + ' ' + data.data[i].category_name + '</label></div></li>')
                        }//for
                    }else{
                        for (var i = 0; i < data.data.length; i++) {
                            if(arr2.indexOf(String(data.data[i].category_id))!=-1 || arr5.indexOf(data.data[i].category_id)!=-1){
                                $("#classSet2").append('<li class="removeEl2 clearfix pl-10 mb-5"><div class="f-l pd-5"><input  name="classification02" type="checkbox" checked disabled value="' + data.data[i].category_id + '" class="checkbox" />' +
                                    '<label class="pl-10"  onclick="goods_listCategory3(3,'+data.data[i].category_id+')">' + data.data[i].category_code + ' ' + data.data[i].category_name + '</label></div></li>')
                            }
                            else{
                                $("#classSet2").append('<li class="removeEl2 clearfix pl-10 mb-5"><div class="f-l pd-5"><input  name="classification02" type="checkbox" disabled value="' + data.data[i].category_id + '" class="checkbox" />' +
                                    '<label class="pl-10" >' + data.data[i].category_code + ' ' + data.data[i].category_name + '</label></div></li>')
                            }
                        }//for
                    }
                    count = 0;
                }else if(arr2.length==0 && arr3.length!=0) {
                    if(count==0){
                        for (var i = 0; i < data.data.length; i++) {
                            $("#classSet2").append('<li class="removeEl2 clearfix pl-10 mb-5"><div class="f-l pd-5"><input  name="classification02" type="checkbox" checked disabled value="' + data.data[i].category_id + '" class="checkbox" />' +
                                '<label class="pl-10" onclick="goods_listCategory3(3,'+data.data[i].category_id+')" >' + data.data[i].category_code + ' ' + data.data[i].category_name + '</label></div></li>')
                        }//for
                    }else{
                        for (var i = 0; i < data.data.length; i++) {
                            if(arr3.indexOf(String(data.data[i].category_id))!=-1 || arr5.indexOf(data.data[i].category_id)!=-1){
                                $("#classSet2").append('<li class="removeEl2 clearfix pl-10 mb-5"><div class="f-l pd-5"><input  name="classification02" type="checkbox" checked disabled value="' + data.data[i].category_id + '" class="checkbox" />' +
                                    '<label class="pl-10"  onclick="goods_listCategory3(3,'+data.data[i].category_id+')">' + data.data[i].category_code + ' ' + data.data[i].category_name + '</label></div></li>')
                            }else{
                                $("#classSet2").append('<li class="removeEl2 clearfix pl-10 mb-5"><div class="f-l pd-5"><input  name="classification02" type="checkbox" disabled value="' + data.data[i].category_id + '" class="checkbox" />' +
                                    '<label class="pl-10">' + data.data[i].category_code + ' ' + data.data[i].category_name + '</label></div></li>')
                            }
                        }//for
                    }
                    count = 0;
                }///else if
                else if(arr2.length==0 && arr3.length==0) {
                    console.log('AAAAAAA');
                    for (var i = 0; i < data.data.length; i++) {
                        $("#classSet2").append('<li class="removeEl2 clearfix pl-10 mb-5"><div class="f-l pd-5"><input  name="classification02" type="checkbox" checked disabled value="' + data.data[i].category_id + '" class="checkbox" />' +
                            '<label class="pl-10" onclick="goods_listCategory3(3,'+data.data[i].category_id+')" >' + data.data[i].category_code + ' ' + data.data[i].category_name + '</label></div></li>')
                    }//for
                    count = 0;
                }
                else if(count==0) {
                    console.log('BBBBBBB');
                    for (var i = 0; i < data.data.length; i++) {
                        $("#classSet2").append('<li class="removeEl2 clearfix pl-10 mb-5"><div class="f-l pd-5"><input  name="classification02" type="checkbox" checked disabled value="' + data.data[i].category_id + '" class="checkbox" />' +
                            '<label class="pl-10" onclick="goods_listCategory3(3,'+data.data[i].category_id+')" >' + data.data[i].category_code + ' ' + data.data[i].category_name + '</label></div></li>')
                    }//for
                    count = 0;
                }

            }
        }
    };
    web.doAjax(root.goodsInter.goods_subCategory, 'post', user_data, succCallBack);
}
var count1 = 0;

function goods_listCategory3(classNum, parentId) {
    sessionStorage.setItem("parentId3", parentId);
    $("#classDiv3").css({
        display: "block"
    });
    $(".removeEl3").remove();
    var user_data = {
        // category_level: classNum,
        category_id: parentId
    }
    var succCallBack = function (data, status, response) {
        if (data.errorCode == "0") {
            if (data.data == null) {
                $("#classSet3").append('<li class="removeEl3 clearfix pl-10 mb-5">无数据</li>');
                $("#classSet3").append('<li  class="removeEl3 clearfix pl-10 mb-5" id="firstClassInp3" style="display: none"><div class="f-l pd-5"><label class="pl-10" id="addLabel3"></label></div><div class=" f-l class-input"><input type="text"  autofocus onkeyup="validClass(this)"  class="input-text radius f-l firstClassId3" name="" placeholder=""></div></li>')
            }
            if(arr3.length!=0){
                if(arr3.length!=0){
                    for (var i = 0; i < data.data.length; i++) {
                        if(arr3.indexOf(String(data.data[i].category_id))!=-1){
                            count1++;
                        }
                    }
                    if(count1==0) {
                        for (var i = 0; i < data.data.length; i++) {
                            $("#classSet3").append('<li class="removeEl3 clearfix pl-10 mb-5"><div class="f-l pd-5"><input  name="classification03" type="checkbox" checked disabled value="' + data.data[i].category_id + '" class="checkbox" />' +
                                '<label class="pl-10" onclick="goods_listCategory4(4,'+data.data[i].category_id+')">' + data.data[i].category_code + ' ' + data.data[i].category_name + '</label></div></li>')
                        }
                        count1 = 0;//初始化值
                    }else{
                        for (var i = 0; i < data.data.length; i++) {
                            if(arr3.indexOf(String(data.data[i].category_id))!=-1){
                                $("#classSet3").append('<li class="removeEl3 clearfix pl-10 mb-5"><div class="f-l pd-5"><input  name="classification03" type="checkbox" checked disabled value="' + data.data[i].category_id + '" class="checkbox" />' +
                                    '<label class="pl-10" onclick="goods_listCategory4(4,'+data.data[i].category_id+')">' + data.data[i].category_code + ' ' + data.data[i].category_name + '</label></div></li>')
                            }
                            else{
                                $("#classSet3").append('<li class="removeEl3 clearfix pl-10 mb-5"><div class="f-l pd-5"><input  name="classification03" type="checkbox"  disabled value="' + data.data[i].category_id + '" class="checkbox" />' +
                                    '<label class="pl-10" onclick="goods_listCategory4(4,'+data.data[i].category_id+')">' + data.data[i].category_code + ' ' + data.data[i].category_name + '</label></div></li>')
                            }
                        }//for
                        count1 = 0;//初始化值
                    }
                }//if
            }
            if(arr3.length==0){
                for (var i = 0; i < data.data.length; i++) {
                    $("#classSet3").append('<li class="removeEl3 clearfix pl-10 mb-5"><div class="f-l pd-5"><input  name="classification03" type="checkbox" checked disabled value="' + data.data[i].category_id + '" class="checkbox" />' +
                        '<label class="pl-10" onclick="goods_listCategory4(4,'+data.data[i].category_id+')">' + data.data[i].category_code + ' ' + data.data[i].category_name + '</label></div></li>')
                }//for
                count1 = 0;//初始化值
            }//if
        }
    };
    return web.doAjax(root.goodsInter.goods_subCategory, 'post', user_data, succCallBack);
}
function goods_listCategory4(classNum, parentId) {
    sessionStorage.setItem("parentId3", parentId);
    $("#classDiv4").css({
        display: "block"
    });
    $(".removeEl4").remove();
    var user_data = {
        // category_level: classNum,
        category_id: parentId
    }
    var succCallBack = function (data, status, response) {
        if (data.errorCode == "0") {
            if (data.data == null) {
                $("#classSet4").append('<li class="removeEl4 clearfix pl-10 mb-5">无数据</li>');
                $("#classSet4").append('<li  class="removeEl4 clearfix pl-10 mb-5" id="firstClassInp4" style="display: none"><div class="f-l pd-5"><label class="pl-10" id="addLabel4"></label></div><div class=" f-l class-input"><input type="text"  autofocus onkeyup="validClass(this)"  class="input-text radius f-l firstClassId4" name="" placeholder=""></div></li>')
            }
            if(arr4.length!=0){
                if(arr4.length!=0){
                    for (var i = 0; i < data.data.length; i++) {
                        if(arr4.indexOf(String(data.data[i].category_id))!=-1){
                            count1++;
                        }
                    }
                    if(count1==0) {
                        for (var i = 0; i < data.data.length; i++) {
                            $("#classSet4").append('<li class="removeEl4 clearfix pl-10 mb-5"><div class="f-l pd-5"><input  name="classification04" type="checkbox" checked disabled value="' + data.data[i].category_id + '" class="checkbox" />' +
                                '<label class="pl-10" >' + data.data[i].category_code + ' ' + data.data[i].category_name + '</label></div></li>')
                        }
                        count1 = 0;//初始化值
                    }else{
                        for (var i = 0; i < data.data.length; i++) {
                            if(arr4.indexOf(String(data.data[i].category_id))!=-1){
                                $("#classSet4").append('<li class="removeEl3 clearfix pl-10 mb-5"><div class="f-l pd-5"><input  name="classification04" type="checkbox" checked disabled value="' + data.data[i].category_id + '" class="checkbox" />' +
                                    '<label class="pl-10">' + data.data[i].category_code + ' ' + data.data[i].category_name + '</label></div></li>')
                            }
                            else{
                                $("#classSet4").append('<li class="removeEl3 clearfix pl-10 mb-5"><div class="f-l pd-5"><input  name="classification04" type="checkbox"  disabled value="' + data.data[i].category_id + '" class="checkbox" />' +
                                    '<label class="pl-10" >' + data.data[i].category_code + ' ' + data.data[i].category_name + '</label></div></li>')
                            }
                        }//for
                        count1 = 0;//初始化值
                    }
                }//if
            }
            if(arr4.length==0){
                for (var i = 0; i < data.data.length; i++) {
                    $("#classSet4").append('<li class="removeEl4 clearfix pl-10 mb-5"><div class="f-l pd-5"><input  name="classification04" type="checkbox" checked disabled value="' + data.data[i].category_id + '" class="checkbox" />' +
                        '<label class="pl-10" >' + data.data[i].category_code + ' ' + data.data[i].category_name + '</label></div></li>')
                }//for
                count1 = 0;//初始化值
            }//if
        }
    };
    return web.doAjax(root.goodsInter.goods_subCategory, 'post', user_data, succCallBack);
}
/*分类设置结束--------------------------------------------------------------------------------------------------------------*/


//编辑指向专题URL
function bianji() {
    $("#topicUrl").removeAttr("readonly");

    $("#addtop").css({
        display: "inline"
    });
}

//保存指向专题URL
function addtopurl() {
    var id = getQueryString('topicId');
    $.ajax({
        url:root.couponInter.updateTopicUrl,
        cache: false,  //禁用缓存
        type: "POST",
        data: {
            topicUrl: $("#topicUrl").val(),
            topicId:id,
        },
        success: function (data) {
            $("#topicUrl").attr("readonly", "readonly");
            $("#addtop").css({
                display: "none"
            });
            location.replace(location.href);
        },
        error: function () {
            $.Huimodalalert('失败！',2000);
        }
    })
}